#coding=utf-8
import requests,json,urllib
import platform_login_api
import mysql_password

#更新个人资料
def update(phone,nickName,email,street):
    password = mysql_password.password(phone)[0]
    s = requests.session()
    userid = mysql_password.password(phone)[1]  # 获取到userid
    headers = platform_login_api.login(phone)[0]  #获取到登录后的headers
    data = ({"avatar":"http://community-fs-api-test.gdgyun.com/uploads/temp/images/3fbea74303a7c277c49f53610c309c20dee56bcc.jpg","email":email,"encryptedPassword":password,"nickName":nickName})  #定义图片、邮箱地址、昵称
    adress_data = ({"province":"北京市","city":"北京市","area":"西城区","street":street,"consigneeMobile":phone,"consigneeName":nickName,"isDefault":"false","userId":str(userid)})  #收货地址数据
    update = s.post('http://community-platform-api-test.gdgyun.com/api/community/userInfo/update',json=data,headers=headers)  #设置邮箱、昵称
    personal_index = s.get('http://community-platform-api-test.gdgyun.com/api/community/userInfo/view',headers=headers)  # 查看个人资料页面是否修改成功
    goldcoin_amount = s.get('http://community-platform-api-test.gdgyun.com/api/community/reward/gold/coinsAmount',headers=headers)  #我的金币
    silvercoin_amount = s.get('http://community-platform-api-test.gdgyun.com/api/community/reward/silverCoins/task',headers=headers) #我的银币
    goods = s.get('http://community-platform-api-test.gdgyun.com/api/community/mall/goods/list?pageIndex=1&pageSize=20',headers=headers)  #金币商城列表页面
    add_adress = s.post('http://community-platform-api-test.gdgyun.com/api/community/mall/consignee/address/add',json=adress_data,headers=headers)  #新增收货地址
    nickname = personal_index.json()["data"]["nickName"]  # 获取修改后的昵称
    email_one = personal_index.json()["data"]["email"]  # 获取修改后的邮箱地址
    #print nickname,email_one
    #判断更新个人资料是否成功
    if str(nickname) == nickName and str(email_one) == email:
        print u'更新个人资料：昵称:'+nickname+'、邮箱:'+email_one+u'成功'
    else:
        print u'更新个人资料：昵称、邮箱失败'
    #判断新增地址是否成功
    if u'新增收货地址成功' in add_adress.text:
        print u'新增地址成功'
    else:
        print u'新增地址失败'
    # print personal_index.text
    # print update.text
    # print goldcoin_amount.text
    # print silvercoin_amount.text
    # print goods.text

if __name__ == '__main__':
    for i in range(0,10,1):
        update('18300020001','雍爆炸','1833335@163.com','天府广场仁和春天1号楼2号'+str(i))